<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>首页</title>
		<link rel="shortcut icon" href="images/hong_favicon.ico" type="image/x-icon">
		<script src="js/mui.min.js"></script>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/common.css" />
		<link rel="stylesheet" type="text/css" href="css/hiconfont.css" />
		<script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			.mui-bar-tab .mui-tab-item.mui-active {
				color: #ff4e00;
			}
		</style>
	</head>

	<body>
		<div id="containPage" class="mui-backdrop" v-show="maskState">

		</div>
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active" href="html/index.html">
				<span class="hIconfont icon-paotui mui-icon"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" href="html/say.html">
				<span class="hIconfont icon-41shuoshuo mui-icon"><span class="mui-badge">9</span></span>
				<span class="mui-tab-label">说说</span>
			</a>
			<a class="mui-tab-item" href="html/message.html">
				<span class="hIconfont icon-xiaoxi mui-icon"></span>
				<span class="mui-tab-label">消息</span>
			</a>
			<a class="mui-tab-item" href="html/my.html">
				<span class="hIconfont icon-wodedangxuan mui-icon"></span>
				<span class="mui-tab-label">我的</span>
			</a>
		</nav>

		<script type="text/javascript">
			//mui初始化
			mui.init({
				swipeBack: true, //启用右滑关闭功能
			});
			var contain_data = new Vue({
				el: "#containPage",
				data: function() {
					return {
						maskState: false
					}

				},
				created: function() {
					this.$nextTick(function() {
						var that = this;
						var flag = false;
						//创建遮罩蒙板
						var mask = mui.createMask(function() {
							//设置点击蒙板不会自动消失
							//但调用close方法关闭mask时，必须返回true
							return flag;
						});
						//监听自定事件
						//打开遮罩蒙板
						window.addEventListener("openMask", function(e) {
							alert('显示')
							mask.show(); //显示遮罩
						});
						//关闭遮罩蒙板
						window.addEventListener("closeMask", function(e) {
							flag = true;
							alert('关闭')
							mask.close();
						});
					})
				}
			})
			var subpages = ["html/index.html", "html/say.html", "html/message.html", "html/my.html"]
			var subpage_style = {
				top: '0',
				bottom: '51px'
			};

			var aniShow = {};

			//创建子页面，首个选项卡页面显示，其它均隐藏；
			mui.plusReady(function() {
				var self = plus.webview.currentWebview();
				localStorage.setItem('appID',self.id);
				for(var i = 0; i < 4; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}
				//当前激活选项
				var activeTab = subpages[0];
				//选项卡点击事件
				mui('.mui-bar-tab').on('tap', 'a', function(e) {
					var targetTab = this.getAttribute('href');
					if(targetTab == activeTab) {
						return;
					}
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						//  fade-in
						plus.webview.show(targetTab, "slide-in-right", 300);
					}
					//隐藏当前; 
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});
				//自定义事件，模拟点击“首页选项卡”
			});
			//自定义事件，模拟点击“首页选项卡”
			window.addEventListener('gohome', function() {
				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				mui.trigger(defaultTab, 'tap');
				//切换选项卡高亮
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
			});
		</script>
	</body>

</html>